package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.busi.api.user.GetUserInfo;
import com.cssw.fyzb.core.exception.BizException;
import com.cssw.fyzb.busi.service.live.AnchorService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 通过用户id获取主播信息
 *
 * @author YangYiQun
 */
@Function(description = "通过用户id获取主播信息", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true)
})
@Component
public class QueryAnchorByUserId implements Action {

    @Autowired
    AnchorService anchorService;

    private static final Logger logger = LoggerFactory.getLogger(GetUserInfo.class);

    @Override
    public Response execute(Request request) throws Exception {
        try {
            Long userId = request.getLong("userId");
            return Response.success().put("data", anchorService.queryAnchorByUserId(userId));
        } catch (Exception e){
            if (e instanceof BizException){
                BizException bz = (BizException)e;
                return Response.fail(bz.getErrMsg(), bz.getErrCode());
            }
            logger.error("", e);
            return Response.fail("操作失败");
        }
    }
}
